package com.wrc.example.controller;

import com.wrc.excel.BeanVO;
import com.wrc.excel.ImportExportUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;

@RestController
@Api(tags = "表格")
//@RequestMapping("/demo/excel/")
public class ExcelController {


    @ApiOperation("导入表格")
    @PostMapping("/importExcel")
    public Object importBdMap(@RequestParam("file") MultipartFile file, HttpServletResponse response) {
        return ImportExportUtil.subscriptParsesExcelEntities(file, BeanVO.class,0,0);
    }

    @ApiOperation("导出表格")
    @PostMapping("/exportExcel")
    public void exportQuestionExcel(HttpServletResponse response) {
        BeanVO beanVO = new BeanVO().setS1("字段1").setS2("字段2").setS3("字段3").setS4("字段4").setS5("字段5").setS6("字段6")
                .setS7("字段7").setS8("字段8").setS9("字段9").setS10("字段10");
        ArrayList<BeanVO> beanVOS = new ArrayList<>();
        beanVOS.add(beanVO);
        ImportExportUtil.exportExcelByApiModelProperty(BeanVO.class,beanVOS,"测试模板.xlsx",response);
    }

    @ApiOperation("下载表格模板")
    @PostMapping("/excelTemplate")
    public ResponseEntity excelTemplate(HttpServletResponse response) {
        return ImportExportUtil.excelTemplate("/excels/测试模板.xlsx","测试模板.xlsx");
    }

}
